package com.fortune.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fortune.base.BaseAPIExcution;
import com.fortune.constants.Constants;
import com.fortune.dto.excution.MSystemParamExcution;
import com.fortune.dto.in.MSystemParam.MSystemParamEditDto;
import com.fortune.entity.MUserInfo;
import com.fortune.enums.MSystemParamEnum;
import com.fortune.service.MSystemParamService;
import com.fortune.vo.mSystemParam.MSystemParam;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(value = "mSystemParam", description = "厂商系统参数管理", tags = {"厂商系统参数管理"})
@RestController
@RequestMapping("mSystemParam")
public class MSystemParamController {
	
	@Autowired
	private MSystemParamService ms;
	@ApiOperation(value = "厂商系统参数列表", nickname = "mSystemParamList", notes = "", tags={ "@岳希伟" })
//	@ApiImplicitParams({
//		@ApiImplicitParam(name="page", value="第几页",paramType="query",dataType="int"),
//		@ApiImplicitParam(name="length", value="每页容量",paramType="query",dataType="int"),
//		@ApiImplicitParam(name="search", value="搜索关键词",paramType="query",dataType="string")
//	})
    @GetMapping(value = "list",
        produces = { MediaType.APPLICATION_JSON_VALUE })
	public BaseAPIExcution<List<MSystemParam>> list(HttpServletRequest request){
		HttpSession session = request.getSession();
		MUserInfo mUserInfo = (MUserInfo) session.getAttribute(Constants.SESSION_M_USER);
		List<MSystemParam> list = ms.list(mUserInfo);
		return new MSystemParamExcution<List<MSystemParam>>(list, MSystemParamEnum.SUCESS);
	}
	@ApiOperation(value = "厂商系统参数设置", nickname = "mSystemParamSet", notes = "", tags={ "@岳希伟" })
	@PostMapping(value = "edit",
    produces = { MediaType.APPLICATION_JSON_VALUE },
    consumes = { MediaType.APPLICATION_JSON_VALUE })
	public BaseAPIExcution<Void> add(HttpServletRequest request,@Validated @RequestBody MSystemParamEditDto editDto) {
		HttpSession session = request.getSession();
		MUserInfo mUserInfo = (MUserInfo) session.getAttribute(Constants.SESSION_M_USER);
		int edit = ms.edit(mUserInfo, editDto);
		if (edit==0) {
			return new MSystemParamExcution<Void>(null, MSystemParamEnum.FALSE);
		}
		return new MSystemParamExcution<Void>(null, MSystemParamEnum.SUCESS);
	}
}
